<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1. 函数的参数默认值
    function add(a, b, c = 10) {    // 一般把给默认参数值的放在最后
      return a + b + c;
    }
    console.log(add(1, 2)); // 13

    // 2. 函数的参数默认值可以和解构赋值结合使用
    function connect({ host = 'localhost', port = 3306, user = 'root', password = 'root' }) {
      console.log(host, port, user, password);
    }
    connect({}); // localhost 3306 root root

    // 还可以这样写
    connect2({
      host: '127.0.0.1',
      port: 3307,
      user: 'admin',
      password: 'admin'
    })
    function connect2({ host, port, user, password }) {
      console.log(host, port, user, password);    // 127.0.0.1 3307 admin admin 
    }


  </script>
</body>

</html>